//
//  FourthRootTableViewController.m
//  结伴
//
//  Created by eliot on 16/8/8.
//  Copyright © 2016年 aleven. All rights reserved.
//

#import "FourthRootTableViewController.h"

#import "MyHeaderView.h"
#import "MyTableViewCell.h"

#import "PersonalHomePageViewController.h"

#import "SettingViewController.h"

#import "LikeViewController.h"
#import "AccomViewController.h"

#import "PersonalMainPageViewController.h"




@interface FourthRootTableViewController ()<UISearchBarDelegate>

@property (nonatomic,strong)NSMutableArray *contentArray;



@end

@implementation FourthRootTableViewController

- (NSMutableArray *)contentArray{
    if (!_contentArray) {
        _contentArray = [NSMutableArray array];
    }
    return _contentArray;
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //导航条设置成透明
    
    self.navigationItem.titleView = [UIView new];
    
//    self.tableView.frame = CGRectMake(0, -64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    
    self.contentArray  = [ NSMutableArray arrayWithObjects:@[@{@"name":@"我的圈子",@"iconName":@"wdqz"}],@[@{@"name":@"新的朋友",@"iconName":@"xpy"},@{@"name":@"结伴",@"iconName":@"jba"},@{@"name":@"相册",@"iconName":@"xc"},@{@"name":@"喜欢",@"iconName":@"xh"}], @[@{@"name":@"设置",@"iconName":@"sz"}],nil];
    
    
    
    //让导航栏透明
    UIColor *colorx = [[UIColor colorWithPatternImage:[UIImage imageNamed:@"001"]]colorWithAlphaComponent:0.01];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage cleImage:colorx] forBarMetrics:UIBarMetricsDefault];
    //    让黑线消失的方法
    self.navigationController.navigationBar.shadowImage=[UIImage new];
}

- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    
     [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
        //设置导航控制器导航上的背景图片，并且拉伸
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navback"] forBarMetrics:UIBarMetricsDefault];
    
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];
   
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    


    
    
    
     self.tableView.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0);
    
    
        __weak typeof(self) weakSelf = self;
    MyHeaderView *header = [[[NSBundle mainBundle] loadNibNamed:@"MyHeaderView" owner:nil options:nil] lastObject];
    
    header.clickHeaderBlcok = ^(){
        
        PersonalMainPageViewController *personalMainPage = [[PersonalMainPageViewController alloc] init];
        
        [weakSelf.navigationController pushViewController:personalMainPage animated:YES];
        
    };
    self.tableView.tableHeaderView = header;
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.contentArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSArray *array = self.contentArray[section];
    
    return array.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    static NSString *ID_main = @"MyTableViewCell";
    
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID_main];
    
    if (!cell) {
        
        cell = [[[NSBundle mainBundle] loadNibNamed:ID_main owner:nil options:nil] lastObject];
    }
    
    NSArray *array  = self.contentArray[indexPath.section];
    
    NSDictionary *dic = array[indexPath.row];
    
    cell.iconName.image = [UIImage imageNamed:dic[@"iconName"]];
    cell.contentLabel.text = dic[@"name"];
    
    return cell;
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.section == 0) {
        PersonalHomePageViewController *per = [[PersonalHomePageViewController alloc] init];
        per.title = @"个人主页";
        per.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:per animated:YES];
    }else if (indexPath.section == 1) {
        
        if (indexPath.row == 1) {
            
            //结伴
            AccomViewController *addBuddy = [[AccomViewController alloc] init];
            [self.navigationController pushViewController:addBuddy animated:YES];
            
        }else if (indexPath.row == 3){
            //喜欢
            LikeViewController *secon = [[LikeViewController alloc]init];
            [self.navigationController pushViewController:secon animated:YES];

            
        }
    }else if (indexPath.section == 2){
        
       // stroryboard 加载@@@@@@@@@@@@@@@@@@@
            //设置
        UIStoryboard *stroryboard = [UIStoryboard storyboardWithName:@"SettingViewController" bundle:nil];
        UIViewController *vc = [stroryboard instantiateInitialViewController];
       
        [self.navigationController pushViewController:vc animated:YES];

    }    
    
    [self performSelectorOnMainThread:@selector(delectCell:) withObject:nil waitUntilDone:YES];
    
}

- (void)delectCell:(id)sender{
    
    [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
    
}


@end
